import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path : '/',
    redirect : '/login'
  },
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/index/index.vue'),
    children: [{
        path: 'back',
        name: 'back',
        component: () => import('../views/index/back.vue'),
      },
      {
        path: 'shop',
        name: 'shop',
        component: () => import('../views/index/shop.vue'),
      },
      {
        path: 'stu',
        name: 'stu',
        component: () => import('../views/index/stu.vue'),
      },
    ]

  },
  {
    path: '/shops',
    name: 'shops',
    component: () => import('../views/shops/index.vue'),
    children: [{
        path: 'shoplist',
        name: 'shoplist',
        component: () => import('../views/shops/shoplist.vue'),
      },
      {
        path: 'shopsize',
        name: 'shopsize',
        component: () => import('../views/shops/shopsize.vue'),
      },
      {
        path: 'shopsort',
        name: 'shopsort',
        component: () => import('../views/shops/shopsort.vue'),
      },
    ]

  },

  {
    path: '/order',
    name: 'order',
    component: () => import('../views/order/index.vue'),
    children: [{
        path: 'ordercontrol',
        name: 'ordercontrol',
        component: () => import('../views/order/ordercontrol.vue'),
      },
      {
        path: 'Invoicecontrol',
        name: 'Invoicecontrol',
        component: () => import('../views/order/Invoicecontrol.vue'),
      },
      {
        path: 'service',
        name: 'service',
        component: () => import('../views/order/service.vue'),
      },
    ]

  },

  {
    path: '/member',
    name: 'member',
    component: () => import('../views/member/index.vue'),
    children: [{
        path: 'points',
        name: 'points',
        component: () => import('../views/member/points.vue'),
      },
      {
        path: 'estate',
        name: 'estate',
        component: () => import('../views/member/estate.vue'),
      },
    ]

  },

  {
    path: '/set',
    name: 'set',
    component: () => import('../views/set/index.vue'),
    children: [{
        path: 'basicsset',
        name: 'basicsset',
        component: () => import('../views/set/basicsset.vue'),
      },
      {
        path: 'logisticsset',
        name: 'logisticsset',
        component: () => import('../views/set/logisticsset.vue'),
      },
      {
        path: 'Adminset',
        name: 'Adminset',
        component: () => import('../views/set/Adminset.vue'),
      },
      {
        path: 'dealset',
        name: 'dealset',
        component: () => import('../views/set/dealset.vue'),
      },
    ]
  },

]

const router = new VueRouter({
  routes
})


router.beforeEach((to, from, next) => {
  if (localStorage.getItem("token")) {
      next();
  } else {
      if (to.path == "/login") {
          next();
      } else {
          next("/login");
      }
  }
});


export default router